<?php

namespace common\models;

use Yii;
use yii\db\ActiveRecord;
use common\models\base\BaseModel;

/**
 * This is the model class for table "cate".
 *
 * @property integer $id
 * @property string $cat_name
 */
class Cate extends BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'cate';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cat_name'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '编号',
            'cat_name' => '分类名称',
        ];
    }

    public static function getAllCate()
    {
        $cate = ['0' => '--请选择分类--'];

        $res = self::find()->asArray()->all();
//        print_r($res);exit;

        if ($res) {
            foreach ($res as $key => $value) {
                $cate[$value['id']] = $value['cat_name'];
            }
        }

        return $cate;
    }
}
